/****************************************************************************
 * Copyright (C) 2009-2011 Dimok
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****************************************************************************/
#ifndef GUI_TOOLTIP_H_
#define GUI_TOOLTIP_H_

#include "gui_image.h"
#include "gui_text.h"

//!Forward declaration
class GuiElement;

class GuiTooltip : public GuiElement
{
	public:
		//!Constructor
		GuiTooltip(const char *t);
		GuiTooltip(const wchar_t *t);
		GuiTooltip(std::string t);
		GuiTooltip(std::wstring t);
		//!Destructor
		virtual ~GuiTooltip();
		
		//!Sets GuiTooltip text
		void SetText(const char * t);
		void SetText(const wchar_t * t);
		void SetText(std::string t) { SetText(t.c_str()); }
		void SetText(std::wstring t) { SetText(t.c_str()); }
		//!Set the fontsize of the text
		void SetFontSize(int size);
		//!Set the maxwidth of the tooltip
		void SetMaxWidth(int size);
		//!Set the color of the text
		void SetColor(GXColor c);
		
		void Show();
		void Hide();
		
		void SetParent(GuiElement * e) { parentElement = e; }
		GuiElement * GetParent() { return parentElement; }
		int GetLeft();
		int GetTop();
		int GetLeftPos() { return xoffset; }
		int GetTopPos() { return yoffset; }
		int GetWidth() { return width; };
		int GetHeight() { return height; }
		void SetSize(int w, int h) { width = w; height = h; }
		void SetVisible(bool v) { visible = v; }
		bool IsVisible() { return visible; }
		void SetState(int s, int c = -1);
		void ResetState() {
			if(state != STATE_DISABLED)
				SetState(STATE_DEFAULT, -1);
		}
		void SetAlpha(int a) { alpha = a; }
		void SetEffect(int e, int a, int t=0);
		void ResetEffects();
		int GetEffect() const { return effects; }
		bool IsAnimated() const { return (GetEffect() > 0); }
		void SetBounds(iRect r) { cutBoundsRect = r; }
		void SetPosition(int x, int y) { xoffset = x; yoffset = y; }
		void SetAlignment(int a) { alignment = a; }
		void Draw();
		void UpdateEffects();
		
		//! Signals
		sigslot::signal2<GuiTooltip *, bool> VisibleChanged;
		
	protected:
		void InternalInit();
		
		int FontSize;
		int MaxWidth;
		GXColor color;
		
		GuiImage * leftImage;
		GuiImage * tileImage;
		GuiImage * rightImage;
		
		GuiImageData * tooltipLeft;
		GuiImageData * tooltipTile;
		GuiImageData * tooltipRight;
		
		GuiText * text;
		
		Timer selectedTimer;
		
		bool visible; //!< Visibility of the Tooltip. If false, Draw() is skipped
		int width; //!< Tooltip width
		int height; //!< Tooltip height
		int xoffset; //!< Tooltip X offset
		int yoffset; //!< Tooltip Y offset
		int zoffset; //!< Tooltip Z offset
		int alpha; //!< Tooltip alpha value (0-255)
		int alignment; //!< Horizontal Tooltip alignment, respective to parent Tooltip
		int state; //!< Tooltip state (DEFAULT, SELECTED, CLICKED, DISABLED)
		int stateChan; //!< Which controller channel is responsible for the last change in state
		iRect cutBoundsRect;
		GuiElement * parentElement; //!< Parent element
		
		//! TODO: Move me to some Animator class
		int xoffsetDyn; //!< Tooltip X offset, dynamic (added to xoffset value for animation effects)
		int yoffsetDyn; //!< Tooltip Y offset, dynamic (added to yoffset value for animation effects)
		int alphaDyn; //!< Tooltip alpha, dynamic (multiplied by alpha value for blending/fading effects)
		int effects; //!< Currently enabled effect(s). 0 when no effects are enabled
		int effectAmount; //!< Effect amount. Used by different effects for different purposes
		int effectTarget; //!< Effect target amount. Used by different effects for different purposes
};

#endif
